package com.youlu.campus.admin.pay;

import com.alibaba.fastjson.JSON;
import com.youlu.campus.admin.utils.AuthUtils;
import com.youlu.campus.entity.PayCategoryConfig;
import com.youlu.campus.entity.VO.req.PayCategoryConfigQueryVO;
import com.youlu.campus.service.pay.PayCategoryConfigService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * V2版本收款推荐页面配置
 */
@Slf4j
@RestController
public class PayCategoryConfigController {
    @Autowired
    private PayCategoryConfigService payCategoryConfigService;

    @PostMapping("/v2/pay/category-config/list")
    public QResult list(@NotNull @RequestBody PayCategoryConfigQueryVO request) {
        log.info(":>>> 开始查询收款推荐位:{}", JSON.toJSONString(request));
        Page<PayCategoryConfig> datas = payCategoryConfigService.list(request);
        return QResult.success(datas);
    }

    @PostMapping("/v2/pay/category-config/create")
    public QResult create(@NotNull @RequestBody PayCategoryConfig request) {
        log.info(":>>> 开始新建收款推荐位:{}", JSON.toJSONString(request));
        request.setCreatorId(AuthUtils.getUserId());
        return QResult.success(payCategoryConfigService.create(request));
    }

    @PostMapping("/v2/pay/category-config/update")
    public QResult update(@NotNull @RequestBody PayCategoryConfig request) {
        log.info(":>>> 开始修改收款推荐位:{}", JSON.toJSONString(request));
        return QResult.success(payCategoryConfigService.update(request));
    }

    @GetMapping("/v2/pay/category-config/find-one")
    public QResult findOne(@RequestParam("id") String id) {
        return QResult.success(payCategoryConfigService.findOne(id));
    }

    @GetMapping("/v2/pay/category-config/delete")
    public QResult delete(@RequestParam("id") String id) {
        return QResult.success(payCategoryConfigService.delete(id));
    }
}
